<template>
  <div class="mod-live-liveUser">
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @on-load="getDataList"
      @refresh-change="refreshChange"
      @row-save="rowSave"
    >
      <template slot-scope="scope" slot="menuLeft">
        <el-button
          v-if="isAuth('live:liveUser:save')"
          icon="el-icon-plus"
          type="primary"
          size="small"
          @click="addOrUpdateHandle()"
          >{{ $t("crud.addTitle") }}</el-button
        >
        <span style="color: red"
          >{{
            $t("liveRoom.newLiveUserNum") +
            $t("liveRoom.platformRemainingQuota")
          }}
          {{ totalNum }} {{ $t("distribution.bcTip4") }}</span
        >
      </template>
      <template slot-scope="scope" slot="menu">
        <!-- <el-button
          v-if="isAuth('live:liveUser:update')"
          icon="el-icon-edit"
          size="small"
          type="primary"
          @click="addOrUpdateHandle(scope.row.liveUserId)"
          >{{ $t("crud.updateBtn") }}</el-button
        > -->
        <el-button
          v-if="isAuth('live:liveUser:delete')"
          type="danger"
          icon="el-icon-delete"
          size="small"
          @click="deleteHandle(scope.row.liveUserId)"
          >{{ $t("crud.delBtn") }}</el-button
        >
      </template>
    </avue-crud>
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdate"
      @refreshDataList="refreshChange"
    ></add-or-update>
  </div>
</template>

<script>
import { tableOption } from '@/crud/live/liveUser'
import AddOrUpdate from './liveUser-add-or-update'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      totalNum: 0,
      deleteTotalNum: 0,
      tableOption: tableOption,
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
  },
  mounted () {
  },
  methods: {
    rowSave(){
      console.log(11)
    },
    getDataList (page) {
      this.dataListLoading = true
      this.getAddProdNum()
      this.$http({
        url: this.$http.adornUrl('/platform/live/liveUser/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize
            },
            this.searchForm
          )
        )
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 获取剩余可新增得数量
    getAddProdNum () {
      this.$http({
        url: this.$http.adornUrl('/platform/live/liveUser/getAddProdNum'),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.shopNum = data.shopNum
        this.totalNum = data.totalNum
        this.deleteShopNum = data.deleteShopNum
        this.deleteTotalNum = data.deleteTotalNum
      })
    },
    deleteHandle (id) {
      this.$confirm(this.$i18n.t('liveRoom.delUserTips') + ' ' + this.deleteTotalNum + this.$i18n.t('distribution.bcTip4') + ',' + this.$i18n.t('seckill.isDeleOper'), this.$i18n.t('remindPop.remind'), {
        confirmButtonText: this.$i18n.t('remindPop.confirm'),
        cancelButtonText: this.$i18n.t('remindPop.cancel'),
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/platform/live/liveUser/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.refreshChange()
            }
          })
        })
      }).catch(() => { })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.page = this.$refs.crud.$refs.tablePage.defaultPage
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    }
  }
}
</script>
<style lang="scss">
.mod-live-liveUser {
}
</style>
